package demo3;


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @基本功能:
 * @program:LinkedMan2
 * @author: 闫哥
 * @create:2024-01-11 09:13:00
 **/
public class MainScreen {

    public static void showScreen(){
        System.out.println("*****************************");
        System.out.println("-------欢迎来到我的电话本-------");
        System.out.println("请输入以下指令：");
        System.out.println("1-新增联系人;");
        System.out.println("2-根据手机号修改联系人姓名");
        System.out.println("3-查询所有联系人;");
        System.out.println("4-根据姓名删除所有联系人;");
        System.out.println("5-根据手机号码删除联系人");
        System.out.println("6-根据姓名查询联系人");
        System.out.println("0-退出电话本");
        System.out.println("*****************************");
    }

    public static void main(String[] args) {


        Scanner scanner = new Scanner(System.in);
        MiOperation miOperation = new MiOperation();
        // ArrayList 这个类是线程安全的吗？ 不安全
        // 怎么变安全？ List 接口中哪些实现 类是线程安全的？
        List<LinkMan> linkManList = new ArrayList<>();
        /**
         * 多态：[多种状态]
         *   一种写法
         *   本身： Dog dog = new Dog();
         *   Animal dog = new Dog();
         *   Flying dog = new Dog();
         *
         *   参数的多态：
         *   public void show(Dog dog){
         *
         *   }
         *   public void show(Flying fly){
         *
         *   }
         *   返回值多态：
         *   public Dog show(){
         *    }
         *    public Flying show(){
         *
         *    }
         */
        while(true){
            // 展示屏幕
            showScreen();
            System.out.println("请输入您的指令：");

            int zhiling = scanner.nextInt();
            switch (zhiling){
                case 1:
                    // 张三 男 18 1899999999
                    System.out.println("请输入新增联系人的姓名 性别 年龄 手机号，以空格隔开");
                    String name = scanner.next();
                    String gender = scanner.next();
                    int age = scanner.nextInt();
                    String phone = scanner.next();
                    LinkMan linkMan = new LinkMan(name,age,gender,phone);
                    List<LinkMan> linkManList1 = miOperation.addLinkMan(linkMan, linkManList);
                    System.out.println(linkManList1==null ? "添加失败":"添加成功");
                    break;
                case 2:

                    System.out.println("请输入你要修改的联系人的手机号 和 姓名，以空格隔开：");
                    String _phone = scanner.next();
                    String _name = scanner.next();
                    List<LinkMan> linkManList2 = miOperation.setLinkMan(_name, _phone, linkManList);
                    System.out.println(linkManList2 == null? "修改失败":"修改成功！");

                    break;
                case 3:
                    miOperation.searchA1l(linkManList);
                    break;
                case 4:
                    System.out.println("请输入你要删除的联系人的姓名");
                    String _name2 = scanner.next();
                    List<LinkMan> linkManList3 = miOperation.deleteLinkManByName(_name2,linkManList);
                    System.out.println(linkManList3 == null? "删除失败":"删除成功！");

                    break;
                case 5:
                    System.out.println("请输入你要删除的联系人的手机号");
                    String _phone2 = scanner.next();
                    List<LinkMan> linkManList4 = miOperation.deleteLinkManByNumber(_phone2,linkManList);
                    System.out.println(linkManList4 == null? "删除失败":"删除成功！");
                    break;
                case 6:
                    System.out.println("请输入你要查询的联系人的姓名");
                    String _name3 = scanner.next();
                    LinkMan linkMan1 = miOperation.searchLinkMan(_name3, linkManList);
                    System.out.println(linkMan1);
                    break;
                case 0:
                    System.out.println("感谢您的使用，下次再会！");
                    System.exit(0);
                default:
                    System.out.println("指令错误，请重新输入");
            }
        }
    }
}